// @FileName  :t5.c
// @Time      :2024/4/5 0:010
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>

struct node {
    int id, stay, arr;
} each[108][108], Q[10086];
//n轮，ls每轮人数,cnt当前周期,qs,qe双指针,win当前窗口还有多久空闲
int n, ls[108], cnt, qs, qe, win[6], wnum = 3, ccnt = 0;

int main() {
    setbuf(stdout, NULL);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &ls[i]);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < ls[i]; j++) {
            each[i][j].id = ++cnt;
            each[i][j].arr = i;
            scanf("%d", &each[i][j].stay);
        }
    }
    while (ccnt < cnt || qs < qe) {
        if (ccnt < n) {
            for (int j = 0; j < ls[ccnt]; j++) //把本轮次到达的人加入队列
                Q[qe++] = each[ccnt][j];
            while (qe - qs >= 7 * wnum && wnum < 5) wnum++;//看情况增加窗口
        }
        for (int k = 1; k <= 5; k++) {//遍历每个窗口
            if (k <= wnum && win[k] <= 0 && qs < qe) {//已开放，窗口空闲，有等待的人
                printf("%d : %d\n", Q[qs].id, ccnt - Q[qs].arr);
                win[k] = Q[qs++].stay;
            }
            win[k]--;
        }
        while (qe - qs < 7 * wnum && wnum > 3) wnum--;//看情况减少窗口
        ccnt++;
    }
}